package net.seehope.foodie.code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import net.seehope.foodie.properties.ProjectProperties;

//验证码bean的装配逻辑
@Configuration
public class ValidateCodeBeanConfig {
	
	@Autowired
	private ProjectProperties properties;

	@Bean
	//下面注解表示:容器中不存在设置的bean的时候，才装配
	//如果写了总的那个验证码接口，那么随便实现一个，比如验证码接口，那图片验证码的默认值也没有了
	@ConditionalOnMissingBean(value = ImageCodeGenerator.class)
	public DefaultImageGeneratorImpl defaultImageGeneratorImpl() {
		DefaultImageGeneratorImpl defaultImageGeneratorImpl = new DefaultImageGeneratorImpl();
		defaultImageGeneratorImpl.setProperties(properties);
		return defaultImageGeneratorImpl;
	}
	
	
	@Bean
	//下面注解表示:容器中不存在设置的bean的时候，才装配
	//如果写了总的那个验证码接口，那么随便实现一个，比如验证码接口，那图片验证码的默认值也没有了
	@ConditionalOnMissingBean(value = SmsCodeSender.class)
	public DefaultSmsCodeSenderImpl defaultSmsCodeSenderImpl() {
		DefaultSmsCodeSenderImpl defaultSmsCodeSenderImpl = new DefaultSmsCodeSenderImpl();
		return defaultSmsCodeSenderImpl;
	}
	
	@Bean
	//下面注解表示:容器中不存在设置的bean的时候，才装配
	//如果写了总的那个验证码接口，那么随便实现一个，比如验证码接口，那图片验证码的默认值也没有了
	@ConditionalOnMissingBean(value = SmsCodeGenerator.class)
	public DefaultSmsCodeGeneratorImpl defaultSmsCodeGeneratorImpl() {
		DefaultSmsCodeGeneratorImpl defaultSmsCodeGeneratorImpl = new DefaultSmsCodeGeneratorImpl();
		defaultSmsCodeGeneratorImpl.setProperties(properties);
		return defaultSmsCodeGeneratorImpl;
	}
	
	
	
}
